/*
 * d=2
 * n=340
 * m=255
 * c=1.33
 * maxlen=2
 * minklen=1
 * maxklen=22
 * minchar=45
 * maxchar=121
 * loop=0
 * numiter=331446
 * seed=0
 */

static int g[] = {
	2, 8, -1, 182, -1, 95, 107, 36, 221, -1,
	53, -1, 97, 65, -1, 198, 10, 161, 175, 21,
	114, -1, 168, 192, 89, 188, 142, 115, 120, -1,
	148, 94, 23, 166, 35, -1, -1, 248, 222, 236,
	197, 151, 232, 221, 45, 167, 0, -1, -1, 200,
	63, 0, 62, 93, 156, 173, -1, 59, -1, 68,
	225, 87, 90, 50, 157, 20, 83, 188, 19, -1,
	177, 114, 231, -1, 202, 15, 162, 22, 0, 96,
	73, 5, 93, 70, 142, 78, 0, 0, 42, 36,
	-1, -1, 7, 69, 94, 0, -1, 0, 95, 92,
	45, 0, 36, 18, -1, 117, 96, 138, 108, 179,
	213, 125, 79, -1, 133, 93, 0, 73, 175, 16,
	213, 109, -1, 96, 2, 204, 169, 38, 142, -1,
	80, -1, 116, 42, 29, 67, 115, 18, 77, 200,
	-1, 7, 98, 95, 77, 233, 72, 155, 222, 248,
	208, -1, 13, -1, 51, 108, 90, 233, 167, -1,
	212, 201, 22, 98, 253, 150, 209, 136, 0, -1,
	116, 121, 120, -1, 108, 159, 190, -1, 64, 68,
	-1, -1, -1, 105, 111, 249, 65, 128, -1, 190,
	208, 133, 112, 11, 209, -1, 88, 210, -1, 45,
	131, 213, 123, 215, 116, 20, -1, 173, 47, 28,
	-1, 27, 18, 148, -1, 110, 72, 21, 176, 73,
	48, 198, 164, 222, 84, 198, 8, 94, 116, 79,
	176, -1, -1, -1, -1, 153, -1, 135, 32, 153,
	0, 132, 62, 154, 202, 215, -1, 56, 183, 227,
	71, 154, 199, 116, -1, -1, -1, 152, 205, -1,
	-1, 3, 64, 134, 226, 140, -1, 252, 189, -1,
	-1, -1, 39, 156, 101, 171, 110, 150, 167, -1,
	219, 222, -1, 0, 168, 109, 0, 152, 49, 116,
	-1, 127, 113, 76, 132, 133, 0, 22, -1, -1,
	242, 76, 212, -1, 193, 82, 193, -1, 107, 204,
	0, 57, -1, 42, 132, 158, 52, 135, 67, 0,
	30, 222, 0, -1, 245, 7, 64, 60, 195, 218,
	-1, -1, 0, 184, 48, 125, 40, -1, 0, 203,
};

static int T0[] = {
	196, 312, 54, 110, 208, 188, 214, 144, 142, 232,
	179, 229, 57, 229, 207, 58, 89, 234, 328, 136,
	283, 239, 143, 326, 149, 325, 215, 136, 230, 319,
	300, 298, 163, 14, 68, 31, 74, 282, 175, 216,
	46, 227, 105, 315, 116, 312, 34, 78, 78, 234,
	86, 22, 133, 229, 8, 155, 214, 95, 291, 316,
	286, 251, 274, 109, 137, 2, 141, 211, 156, 188,
	87, 202, 287, 193, 49, 276, 37, 64, 188, 140,
	77, 79, 43, 301, 168, 78, 11, 158, 321, 204,
	111, 315, 197, 170, 58, 292, 125, 219, 117, 112,
	56, 26, 315, 329, 176, 200, 319, 308, 136, 39,
	108, 213, 330, 23, 46, 158, 314, 58, 316, 295,
	134, 299, 142, 203, 130, 72, 155, 255, 291, 144,
	27, 7, 171, 214, 208, 219, 286, 59, 188, 83,
	311, 168, 168, 301, 192, 215, 332, 38, 145, 180,
	205, 151, 140, 7, 
};

static int T1[] = {
	217, 303, 37, 17, 248, 268, 232, 48, 139, 67,
	336, 102, 220, 306, 26, 112, 210, 271, 283, 42,
	8, 139, 183, 59, 249, 252, 116, 299, 232, 158,
	291, 109, 121, 328, 339, 241, 129, 103, 290, 268,
	42, 158, 30, 262, 124, 268, 246, 207, 199, 190,
	121, 207, 201, 304, 138, 110, 88, 127, 281, 320,
	285, 233, 302, 278, 221, 173, 51, 222, 276, 1,
	150, 318, 31, 53, 112, 28, 193, 157, 6, 298,
	28, 129, 164, 329, 52, 69, 333, 28, 306, 45,
	59, 131, 281, 79, 105, 83, 115, 325, 123, 179,
	148, 317, 129, 307, 270, 337, 89, 272, 154, 307,
	102, 54, 309, 267, 44, 21, 208, 249, 49, 175,
	167, 321, 306, 108, 272, 283, 63, 47, 269, 186,
	98, 289, 35, 100, 128, 178, 97, 90, 110, 124,
	57, 213, 178, 26, 140, 94, 260, 220, 216, 181,
	55, 43, 162, 233, 
};

#ifndef perfhash_tolower
#define perfhash_tolower(c) gumbo_tolower(c)
#endif

static int perfhash(const unsigned char *key, int len)
{
	int i;
	int n;
	unsigned f0, f1;
	const unsigned char *kp = key;

	if (len < 1 || len > 22)
		return -1;

	for (i=-45, f0=f1=0, n=0; n<len; ++n) {
		int c = kp[n];
		c = perfhash_tolower(c);
		if (c < 45 || c > 121)
			return -1;
		f0 += T0[i + c];
		f1 += T1[i + c];
		i += 77;
		if (i >= 109)
			i = -45;
	}

	f0 %= 340;
	f1 %= 340;

	return (g[f0] + g[f1]) % 255;
}
